﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using TTGame;

/*
 * AnimEvents
 * 用于技能编辑器上的各种事件
 * ！！！不再使用！！！
 *
 * 依赖：
 *
 * ！不写重复代码！
 * @author TTun
 * @date 7/24/2017 10:24:37 AM
 */
namespace TTGameEngine {

public enum AnimEventType {
    //Event_PlayVoice,
    //Event_Shock,
    Event_PlayParticle,
    Event_ParticleMuzzle,
}


[System.Serializable]
public class AnimationEventData : System.IComparable<AnimationEventData> {
    public string clipName;
    public AnimEventType animEventType;
    public string functionName = null;
    public float time;
    [HideInInspector]
    public float normalTime = -1.0f;
    public string par1;
    public string par2;
    public string par3;
    [HideInInspector]
    public Transform relationNode = null;

    public BaseEventInfo m_parseInfo;

    public int CompareTo(AnimationEventData other) {
        float sub = normalTime - other.normalTime;
        if(sub < 0) {
            return -1;
        } else if(sub == 0) {
            return 0;
        }
        return 1;
    }
}

public abstract class BaseEventInfo {
    public virtual void EventAction(Puppet listenPuppet) { }
}

/// <summary>
/// part1:Pos node
/// relation：Effect Obj
/// </summary>
public class ParticleEvent : BaseEventInfo {
    public ParticleControl m_pControl = null;
    public bool m_muzzleShoot = false;
    public string posNodeName;
    public ParticleEvent(AnimationEventData data, bool muzzle = false) {

        if(data != null && data.relationNode) {
            m_pControl = data.relationNode.GetComponent<ParticleControl>();
        }
        m_muzzleShoot = muzzle;
        posNodeName = data.par1;
    }
    public override void EventAction(Puppet listenPuppet) {
        //muzzleTF
        Transform relationTF = null;
        if(string.IsNullOrEmpty(posNodeName)) {
            relationTF = listenPuppet.objTF;
        } else {
            relationTF = listenPuppet.PosRootTF.Find(posNodeName);
            RelationNode relate = relationTF.gameObject.GetComponent<RelationNode>();
            if(relate != null) {
                relationTF = relate.BindTF;
            }
        }

        if(m_pControl) {
            m_pControl.Init(relationTF);
            if(m_muzzleShoot) {
                //m_pControl.OutBreakMuzzle(listenPuppet);
            } else {
                m_pControl.OutBreak(listenPuppet);
            }
        }
    }
}


//     public class PlayVoiceEvent : BaseEventInfo
//     {
//         public string[] m_audioNames;
//         public int m_priority;
//         public float[] m_durration;
//         public PlayVoiceEvent(AnimationEventData data)
//         {
//             m_audioNames = data.par1.Split(';', System.StringSplitOptions.RemoveEmptyEntries);
//             m_priority = 0;
//             if (!string.IsNullOrEmpty(data.par2))
//             {
//                 m_priority = int.Parse(data.par2);
//             }
//             if (!string.IsNullOrEmpty(data.par3))
//             {
//                 string[] times = data.par3.Split(';', System.StringSplitOptions.RemoveEmptyEntries);
//                 m_durration = new float[times.Length];
//                 for (int i = 0; i < times.Length; i++)
//                 {
//                     m_durration[i] = float.Parse(times[i]);
//                 }
//             }
//         }
//         public override void EventAction(Puppet listenPuppet)
//         {
//             if (m_audioNames != null && m_audioNames.Length > 0)
//             {
//                 string audioName = m_audioNames[Random.Range(0, m_audioNames.Length)];
//                 float durration = 0f;
//                 if (m_durration != null && m_durration.Length > 0)
//                 {
//                     if (m_durration.Length == 1) { durration = m_durration[0]; }
//                     else if (m_durration.Length == 2) { durration = Random.Range(m_durration[0], m_durration[1]); }
//                     else { durration = m_durration[Random.Range(0, m_durration.Length)]; }
//                 }
//                 listenPuppet.AddPlayingAudio(audioName, m_priority, durration);
//             }
//         }
//     }
//     public class ShockEvent : BaseEventInfo
//     {
//         public float m_shakeAmplitude;
//         public float m_shakeLastTime;
//         public ShockEvent(AnimationEventData data)
//         {
//             m_shakeAmplitude = float.Parse(data.par1);
//             m_shakeLastTime = float.Parse(data.par2);
//         }
//         public override void EventAction(Puppet listenPuppet)
//         {
//             GameplayController.Instance.cameraManager.Shake(m_shakeLastTime, m_shakeAmplitude);
//         }
//     }

}
